<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>添加用户</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/static/bootstrap-3.3.5-dist/css/bootstrap.css" />

</head>
<body>
	<div class="row-fluid" style="margin-top: 10px;">
		<div class="col-md-6">
			<h3>修改密码</h3>
			<form role="form" class="form-horizontal"
				action="${pageContext.request.contextPath}/alterPasswordAdminAction "
				method="post" id="checkForm">
				<div class="form-group">
					<label class="col-md-3 control-label" for="username">用户名</label>
					<div class="col-md-9">
						<input class="form-control" name="userBean.username" type="text"
							id="username" placeholder="Username" disabled="disabled"
							value="${bean.username }" /> <input type="hidden" name="bean.id"
							id="id" value="${bean.id }" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-3 control-label" for="inputPassword">密码</label>
					<div class="col-md-9">
						<input type="text" name="userBean.password" class="form-control"
							id="password" onblur="checkpwd()">
						<div width="12px" id="temp">
							<nobr>
								<font color="red">*</font>
							</nobr>
						</div>
					</div>

				</div>
				<div class="form-group">
					<label class="col-md-3 control-label" for="inputPassword">新密码</label>
					<div class="col-md-9">
						<input type="text" name="password1" class="form-control"
							id="password1" placeholder="password" />
						<div width="12px" id="temp">
							<nobr>
								<font color="red">*</font>
							</nobr>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-3 control-label" for="inputPassword">确认密码</label>
					<div class="col-md-9">
						<input type="text" name="password2" class="form-control"
							id="password2" placeholder="confirmPassword" />
						<div width="12px" id="temp">
							<nobr>
								<font color="red">*</font>
							</nobr>
						</div>
					</div>
				</div>
				<div class="form-group"></div>
				<div class="form-group">
					<div class="col-md-offset-3 col-md-9">
						<button type="submit" class="btn btn-primary btn-block">
							修改</button>
					</div>
				</div>
			</form>
		</div>
		<div class="col-md-3"></div>
	</div>
	<script
		src="${pageContext.request.contextPath}/static/js/jquery-1.12.1.js"
		type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/static/bootstrap-3.3.5-dist/js/bootstrap.js"
		type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/static/js/jquery.validate.js"
		type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/static/js/myValidate.js"
		type="text/javascript"></script>
	<script type="text/javascript">
		function checkpwd() {
			var id = document.getElementById("id").value;
			jQuery(function() {
				var password = $.trim($("#password").val());//获得表单的值. 
				$
						.ajax({
							url : "${pageContext.request.contextPath}/checkpwdAdminAction?id="
									+ id, //请求服务器url地址.  
							data : {
								password : password
							},//获得表单里面的值,传入服务器中..  
							cache : false,
							success : function(response) {
								if (response == "false") {
									document.getElementById('password').value = '';
									document.getElementById('temp').innerHTML = '<nobr><font color="red">原始密码错误!</font></nobr>';
								} else {
									document.getElementById('temp').innerHTML = '<nobr><font color="#228B22">原始密码可用</font></nobr>';
								}
							}
						})
			});
		}
		var MyValidator = function() {
			var handleSubmit = function() {
				$('.form-horizontal').validate(
						{
							errorElement : 'span',
							errorClass : 'help-block',
							focusInvalid : false,
							rules : {
								'userBean.password' : {
									required : true
								},
								'password1' : {
									required : true
								},
								'password2' : {
									required : true,
									equalTo : "#password1"
								}
							},
							messages : {
								'userBean.password' : {
									required : "请输入密码",
								},
								'password1' : {
									required : "请输入密码"
								},
								'password2' : {
									required : "请输入重复密码",
									equalTo : "两次输入的密码不一致"
								}
							},

							highlight : function(element) {
								$(element).closest('.form-group').addClass(
										'has-error');
							},

							success : function(label) {
								label.closest('.form-group').removeClass(
										'has-error');
								label.remove();
							},

							errorPlacement : function(error, element) {
								element.parent('div').append(error);
							},

							submitHandler : function(form) {
								form.submit();
							}
						});

				$('.form-horizontal input').keypress(function(e) {
					if (e.which == 13) {
						if ($('.form-horizontal').validate().form()) {
							$('.form-horizontal').submit();
						}
						return false;
					}
				});
			};
			return {
				init : function() {
					handleSubmit();
				}
			};

		}();

		MyValidator.init();
	</script>
</body>
</html>
